package com.api.util.repo.impl;

import com.api.test.Api;
import com.api.util.repo.DtoAccessor;
import com.api.util.repo.DtoFactory;
import com.api.util.repo.DtoProperties;

public class ZyncroRepo {

	private final DtoAccessor dtoAccessor;

	public ZyncroRepo(String propertiesFile, Api api) {

		DomainDtoFactory domainFactory = new DomainDtoFactory(api);
		DtoProperties dtoRepository = new DtoProperties(propertiesFile);

		this.dtoAccessor = new DtoAccessor(dtoRepository);
		this.dtoAccessor.registerFactory(domainFactory);
	}

	public Domain getDomain(String domainName) {
		return dtoAccessor.getDto(domainName, Domain.class);
	}

	public DomainUser getMainUser(String domainName) {
		this.getDomain(domainName);
		return dtoAccessor.getDto(domainName, DomainUser.class);
	}

	public <T> T getPropertyDto(String property, DtoFactory<T> factory) {
		return dtoAccessor.getDto(property, factory);
	}

	// public DomainUser getSimpleUser(String domainName, String domainUser) {
	// DomainUser mainAdmin = this.getMainUser(domainName);
	// String name = String.format("%s-%s", domainName, domainUser);
	//
	// DtoFactory<DomainUser> factory = new DomainUserDtoFactory(api, mainAdmin);
	// return dtoAccessor.getDto(name, DomainUser.class, factory);
	// }
	//
	// public String getDepartment(String domainName, String domainDepartment) {
	// DomainUser mainAdmin = this.getMainUser(domainName);
	// String name = String.format("%s-%s", domainName, domainDepartment);
	// DtoFactory<String> factory = new DepartmentDtoFactory(api, mainAdmin);
	// return dtoAccessor.getDto(name, String.class, factory);
	// }
}
